/*
 * @Author: maybe 
 * @Date: 2019-06-26 10:33:22 
 * @instrucdut: 用于统一处理正则验证
 * @Last Modified time: 2019-06-26 10:33:46
 */

const regArr=[{
    'phone': '^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$'
}]

export const regPhone = (value) =>{
    var phoneRe = new RegExp(regArr[0].phone)
    return phoneRe.test(value);
}
//时间formatDate的方法
export function formatDate(date, fmt) {
    date = eval(date);
    fmt = fmt || 'yyyy-MM-dd hh:mm:ss';
    date = new Date(date);
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
    };
    for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
            let str = o[k] + '';
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : ('00' + str).substr(str.length));
        }
    }
    return fmt;
};



// 保留小数的方法，不四舍五入
export function numFilter (value,i) {
    // 截取当前数据到小数点后三位
    i = i || 3;
    let tempVal = parseFloat(value).toFixed(i)
    let realVal = tempVal.substring(0, tempVal.length - 1)
    return realVal
}